package hu.debrecen.adastra.card.web.dev;

import hu.debrecen.adastra.card.repository.AccountRepository;
import hu.debrecen.adastra.card.repository.UserConnectionRepository;
import hu.debrecen.adastra.card.repository.domain.Account;
import hu.debrecen.adastra.card.repository.domain.social.UserConnection;

import java.io.IOException;
import java.util.Collection;

import javax.inject.Inject;
import javax.servlet.ServletException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Lists;

@Controller
public class DatabaseController {

	private final AccountRepository accountRepository;

	private final UserConnectionRepository userConnectionRepository;
	
	@Inject
	public DatabaseController(AccountRepository accountRepository, UserConnectionRepository userConnectionRepository) {
		this.accountRepository = accountRepository;
		this.userConnectionRepository = userConnectionRepository;
	}

	@RequestMapping(value = "/accounts", method = RequestMethod.GET)
	@ResponseBody
	public Collection<Account> getAccounts() throws ServletException, IOException {
		return Lists.newArrayList(accountRepository.findAll());
	}
	
	@RequestMapping(value = "/userconnection", method = RequestMethod.GET)
	@ResponseBody
	public Collection<UserConnection> getUserConnection() throws ServletException, IOException {
		return Lists.newArrayList(userConnectionRepository.findAll());
	}

}
